package com.ukao.cashregister.adapter;

import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;

import com.mcxtzhang.commonadapter.rv.CommonAdapter;
import com.mcxtzhang.commonadapter.rv.ViewHolder;
import com.ukao.cashregister.R;
import com.ukao.cashregister.bean.RechargeBean;
import com.ukao.cashregister.utils.CheckUtils;

import java.util.ArrayList;

import static com.ukao.cashregister.R.id.giftAmount;

/**
 * Created by ukaodev on 2017/6/14.
 */

public class RechargeDialogAdapter extends CommonAdapter<RechargeBean> {



    public RechargeDialogAdapter(Context context, ArrayList<RechargeBean> datas ) {
        super(context, datas, R.layout.adapter_recharge_dialog);
    }




    @Override
    public void convert(ViewHolder holder, RechargeBean item) {
        TextView amount= holder.getView(R.id.amount);
        TextView mgiftAmount= holder.getView(giftAmount);
        TextView mdetail= holder.getView(R.id.detail);
        ImageView checkIamge= holder.getView(R.id.check_iamge);
        amount.setText("充"+CheckUtils.isEmptyNumber(item.getAmount())+"元");
        if (item.isIsSendAmt()){
            mgiftAmount.setText("  送"+CheckUtils.isEmptyNumber(item.getGiftAmount())+"元");
        }else{
            mgiftAmount.setText("");
        }
        StringBuffer   mStringBuffer=new StringBuffer();

        if (item.isIsSendPoint()){/*积分*/
            mStringBuffer.append("送"+item.getGiftPoint()+"积分,");

        }
        if (item.isIsSendCoupon()){/*优惠券*/
            mStringBuffer.append("送"+item.getCouponCnt()+"优惠券,");

        }
        if (item.isIsSendCard()){/*会员卡*/
            mStringBuffer.append("可获得"+item.getCardName()+"一张,");
        }

        String    sendMsg=mStringBuffer.toString();
        if (sendMsg.endsWith(",")){
            mdetail.setText("  ("+sendMsg.substring(0,sendMsg.length()-1)+")");
        }else{
            mdetail.setText("");
        }



       if (item.isCheck()){
           holder.itemView.setBackgroundResource(R.drawable.adderss_check_bg);
           checkIamge.setBackgroundResource(R.drawable.check_box_check);
       }else{
           checkIamge.setBackgroundResource(R.drawable.check_box_normal);
           holder.itemView.setBackgroundResource(R.drawable.shape_glay_normal_bg);

       }

    }


}
